{extend name='common/common' /}

{block name='style'}
<style media="screen">
.el-card.box-card{
	overflow: auto;
}
.el-card__body{
	min-width: 770px;
}
.treeBox {
	padding: 15px;
	width: 520px;
	border: 1px solid #dcdfe6;
	border-radius:4px;
}
</style>
{/block}

{block name="component"}
<div id="mapToolBox">
	<el-dialog title="描点（右键添加点，可以拖动的哦）" :visible.sync="showMap" fullscreen>
		<iframe id="aMap" src="{:url('Gis/map_addpoint_tool')}" width="100%" height="600" frameborder="0"></iframe>
		<div slot="footer" class="dialog-footer">
			<el-button @click="showMap = false">取消</el-button>
			<el-button type="success" @click="surePoint">确定</el-button>
		</div>
	</el-dialog>
</div>
<script type="text/javascript">
var map = new Vue({
	el:"#mapToolBox",
	data:{
		showMap:false,
	},
	methods:{
		surePoint() {
			if(aMap.contentWindow.mapBox.isAdd){
				var i = this.index;
				var position = aMap.contentWindow.mapBox.getPosition();
				main.form.lnglat= position.lng+","+position.lat;
				this.showMap = false;
				var address = aMap.contentWindow.mapBox.getLocation(position.lng,position.lat,this.getAddress);
			}else{
				this.showMap = false;
			}
		},
		getAddress(res) {
			main.form.address = res.address;
		}
	}
})
</script>
{/block}

{block name="content"}
<el-row>
	<el-col :md="18">
		<el-card class="box-card">
			<div slot="header">企业信息注册</div>
			<div>
				<el-form
					label-width="130px" :model="form" inline="true"
					:rules="rules" ref="form" class="curForm">
					<el-form-item label="企业登录编码" prop="user_name">
						<el-input v-model="form.user_name" disabled></el-input>
					</el-form-item>
					<el-form-item label="所属地区" prop="depart_name">
						<el-input v-model="form.depart_name" disabled></el-input>
					</el-form-item><br>
					<el-form-item label="政府平台账号" prop="government_uname">
						<el-input v-model="form.government_uname"></el-input>
					</el-form-item>
					<el-form-item label="政府平台密码" prop="government_pwd">
						<el-input v-model="form.government_pwd"></el-input>
					</el-form-item><br>
					<el-form-item label="企业名称" prop="name">
						<el-input v-model="form.name"></el-input>
					</el-form-item>
					<el-form-item label="地址描点" prop="lnglat">
						<el-input v-model="form.lnglat" readonly
							@focus="addMapoint">
						</el-input>
					</el-form-item><br>
					<el-form-item label="企业地址" prop="address">
						<el-input v-model="form.address" type="textarea" style="width:550px;"></el-input>
					</el-form-item><br>
					<el-form-item label="联系人" prop="linkMan">
						<el-input v-model="form.linkMan"></el-input>
					</el-form-item>
					<el-form-item label="办公电话" prop="tel">
						<el-input v-model="form.tel"></el-input>
					</el-form-item><br>
					<el-form-item label="法人代表" prop="legalPerson">
						<el-input v-model="form.legalPerson"></el-input>
					</el-form-item>
					<el-form-item label="站点编码" prop="code">
						<el-input v-model="form.code"></el-input>
					</el-form-item><br>
					<el-form-item label="邮政编码" prop="postalcode">
						<el-input v-model="form.postalcode"></el-input>
					</el-form-item>
					<el-form-item label="从业人数" prop="employee">
						<el-input v-model="form.employee"></el-input>
					</el-form-item><br>
					<el-form-item label="注册资本(万元)" prop="assets">
						<el-input v-model="form.assets"></el-input>
					</el-form-item>
					<el-form-item label="企业网址" prop="website">
						<el-input v-model="form.website"></el-input>
					</el-form-item><br>
					<el-form-item label="传真" prop="fax">
						<el-input v-model="form.fax"></el-input>
					</el-form-item>
					<el-form-item label="手机" prop="mobile">
						<el-input v-model="form.mobile"></el-input>
					</el-form-item><br>
					<el-form-item label="电商平台名称" prop="platform">
						<el-input v-model="form.platform"></el-input>
					</el-form-item>
					<el-form-item label="电商平台网址" prop="plWebsite">
						<el-input v-model="form.plWebsite"></el-input>
					</el-form-item><br>
					<el-form-item label="手机APP下载链接" prop="appUrl">
						<el-input v-model="form.appUrl"></el-input>
					</el-form-item>
					<el-form-item label="微信公众号" prop="wechat">
						<el-input v-model="form.wechat"></el-input>
					</el-form-item><br>
					<el-form-item label="消费商品品类" prop="buy">
						<div class="treeBox">
							<el-tree :data="goodsCateData" node-key="commid"
								show-checkbox :props="props" indent="32" ref="buyTree">
							</el-tree>
						</div>
					</el-form-item><br>
					<el-form-item label="销售商品品类" prop="sell">
						<div class="treeBox">
							<el-tree :data="goodsCateData" node-key="commid_2"
								show-checkbox :props="props" indent="32" ref="sellTree">
							</el-tree>
						</div>
					</el-form-item><br>
					<el-form-item label="备注" prop="remark">
						<el-input v-model="form.remark" style="width:550px;"
							type="textarea">
						</el-input>
					</el-form-item><br>
					<el-form-item label=" ">
						<el-button plain type="primary" @click="subForm">提交</el-button>
					</el-form-item>
				</el-form>
			</div>
		</el-card>
	</el-col>
</el-row>
{/block}

{block name='script'}
<script type="text/javascript">
var main = new Vue({
	el:"#main",
	data:{
		loading:false,
		optionGroup:'',
		goodsCateData:"",
		props:{
			label:"name",
		},
		form:{
			uid:"{$uid}",
			user_name:"{$user.user_name}",
			depart_name:"{$depart.name}",
			depart_id:"{$depart.id}",
			government_uname:"",government_pwd:"",name:"",
			address:"",linkMan:"",legalPerson:"",code:"",tel:"",
			postalcode:"",employee:"",assets:"",website:"",fax:"",
			mobile:"",platform:"",plWebsite:"",appUrl:"",wechat:"",
			buy:[],sell:[],remark:"",lnglat:""
		},
		rules:{
			government_uname:[{required:true,message:'请输入政府平台账号',trigger:['blur','change']}],
			government_pwd:[{required:true,message:'请输入政府平台密码',trigger:['blur','change']}],
			name:[{required:true,message:'请输入企业名称',trigger:['blur','change']}],
			address:[{required:true,message:'请输入企业地址',trigger:['blur','change']}],
			linkMan:[{required:true,message:'请输入联系人',trigger:['blur','change']}],
			legalPerson:[{required:true,message:'请输入法人代表',trigger:['blur','change']}],
			tel:[{required:true,message:'请输入办公电话',trigger:['blur','change']}],
			code:[{required:true,message:'请输入站点编码',trigger:['blur','change']}],
			lnglat:[{required:true,message:'请描点',trigger:['blur','change']}],
			buy:[{required:true,message:'请选择代买类别',trigger:['blur','change']}],
			sell:[{required:true,message:'请描代卖类别',trigger:['blur','change']}],
		}
	},
	mounted:function () {
		this.getCheckBoxes();
	},
	methods:{
		getCheckBoxes() {
			$.post('./getGoodsCateTree',function(res){
				main.goodsCateData = res.data;
			});
		},
		addMapoint() {
			$("#aMap").attr('src',"{:url('Gis/map_addpoint_tool')}?r=Math.random(0,9999)");
			map.showMap = true;
		},
		subForm() {
			this.form.buy = this.$refs.buyTree.getCheckedKeys();
			this.form.sell = this.$refs.sellTree.getCheckedKeys();
			this.$refs['form'].validate((valid) => {
				if (valid) {
					var param = this.form;
					$.post("./becomeCompany",param,function(res){
						if(res.code == 1){
							main.$notify({title:"成功",type:"success",message:res.msg})
						}else{
							main.$notify.error({title:"错误",message:res.msg})
						}
					})
				}
        	});
		}
	}
})
</script>
{/block}
